package com.controller;

import com.bean.dangBean.Role;
import com.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;


/**
 * 界面业务控制器
 */
@Controller
public class ViewController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/")
    public String home(){
        System.out.println(">>> home page");
        return "login";
    }

    @RequestMapping("login")
    public String login(Model model, HttpSession session){

        System.out.println(">>>  login page");
        model.addAttribute("msg",session.getAttribute("msg"));
        session.removeAttribute("msg");

        return "login";
    }

    @RequestMapping("main")
    public String index(Model model, HttpSession session){

        System.out.println(">>>  main page");
        model.addAttribute("loginInfo",session.getAttribute("loginInfo"));
        model.addAttribute("userRole",session.getAttribute("userRole"));
        model.addAttribute("currUrl",session.getAttribute("currUrl"));
        model.addAttribute("currParam",session.getAttribute("currParam"));

        return "main";
    }

    @RequestMapping("mainTwo")
    public String mainTwo(HttpSession session){

        System.out.println(">>>  mainTwo page");
        session.setAttribute("loginInfo",session.getAttribute("loginInfo"));
        session.setAttribute("currUrl",session.getAttribute("currUrl"));
        session.setAttribute("currParam",session.getAttribute("currParam"));

        return "redirect:/main";
    }

    @RequestMapping("hello")
    public String welcome(Model model, HttpSession session){
        System.out.println(">>> hello page");

        return "hello";
    }



    @RequestMapping("detail")
    public String user_Package(Model model, HttpSession session){

        System.out.println(">>>  detail page");

        model.addAttribute(session.getAttribute("providerInfo"));
        model.addAttribute(session.getAttribute("commodityInfo"));
        session.removeAttribute("providerInfo");
        session.removeAttribute("commodityInfo");

        return "detail";
    }

    @RequestMapping("sales/cashierOrder")
    public String cashierOrder(Model model, HttpSession session){
        //收银页
        System.out.println(">>> sales/cashierOrder-Page");
        return "sales/cashierOrder";
    }
    @RequestMapping("queryCashierOrderList")
    public String query(Model model){
        //点交易记录后显示的页面
        System.out.println(">>>query queryCashierOrderList");
        return "sales/cashierOrderList";
    }
    @RequestMapping("salesReturn")
    public String salesReturn(Model model){
        //点销售退货后显示的页面
        System.out.println(">>>salesReturn");
        return "salesReturn/salesReturn";
    }
    @RequestMapping("salesReturnRecord")
    public String salesReturnRecord(Model model){
        //点销售退货后显示的页面
        System.out.println(">>>salesReturnRecord");
        return "salesReturn/salesReturnRecord";
    }

    @RequestMapping("empAdd")
    public String add(Model model, HttpSession session){
        System.out.println(">>> add page");
        List<Role> roleList = employeeService.queryRole();
        model.addAttribute("roleList", roleList);
        return "page/emp/empAdd";
    }
    @RequestMapping("empUpdate")
    public String update(Model model, HttpSession session){
        System.out.println(">>> update page");

        session.setAttribute("prevUrl", "/detail");

        session.setAttribute("currUrl", "/update");
        model.addAttribute("empInfo", session.getAttribute("empInfo"));

        return "page/emp/empUpdate";
    }

    @RequestMapping("empDetail")
    public String detail(Model model, HttpSession session){

      /*  session.setAttribute("prevUrl", "/emp/query");

        session.setAttribute("currUrl", "/emp/unique");*/
        System.out.println(session.getAttribute("empInfo")+"45");
        model.addAttribute("empInfo", session.getAttribute("empInfo"));
        return "page/emp/empDetail";
    }



    @RequestMapping("conAdd")
    public String conadd(Model model, HttpSession session){
        System.out.println(">>> conAdd page consumer");
        return "page/consumer/conAdd";
    }

    @RequestMapping("conUpdate")
    public String conupdate(Model model, HttpSession session){
        System.out.println(">>> conUpdate page consumer");

     /*   session.setAttribute("prevUrl", "/detail");

        session.setAttribute("currUrl", "/update");*/
        model.addAttribute("conInfo", session.getAttribute("conInfo"));

        return "page/consumer/conUpdate";
    }

    @RequestMapping("conDetail")
    public String condetail(Model model, HttpSession session){

        session.setAttribute("prevUrl", "/con/query");

        session.setAttribute("currUrl", "/con/unique");
        model.addAttribute("conInfo", session.getAttribute("conInfo"));
        return "page/consumer/conDetail";
    }

    @RequestMapping("balAdd")
    public String balAdd(Model model, HttpSession session){
        System.out.println(">>> balAdd page consumer");
        return "page/bal/balAdd";
    }

}
